﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
        <table class="easyui-datagrid" id="newTypelist" data-options="rownumbers:true,toolbar:'#Typenewstb'">

        </table>
        <div id="Typenewstb" style="padding: 2px 5px;">
            <div id="ft" style="padding: 2px 5px;">
                <a href="#" class="easyui-linkbutton" iconcls="icon-add" onclick="addnewType()" plain="true">添加新闻</a>
                <a href="#" class="easyui-linkbutton" iconcls="icon-remove" onclick="delnewType()" plain="true">删除选中</a>
            </div>
        </div>
        <div id="newsTypeaddwin" class="easyui-dialog" title="添加" style="width: 200px; height: 100px;"
            data-options="iconCls:'icon-add',resizable:true,modal:true,buttons:'#add_bt',closed: true">
            <div style="margin: 0 auto; text-align: center;">
                新闻类型:<input type="text" id="newtaddypetitle" style="width: 100px">
                <a href="#" class="easyui-linkbutton" onclick="bt_addType()">保存</a>
                <a href="#" class="easyui-linkbutton" onclick="$('#newsTypeaddwin').dialog('close')">关闭</a>
            </div>
        </div>
        <div id="newsTypeEditwin" class="easyui-dialog" title="编辑" style="width: 200px; height: 100px;"
            data-options="iconCls:'icon-edit',resizable:true,modal:true,buttons:'#add_bt',closed: true">
            <div style="margin: 0 auto; text-align: center;">
                新闻类型:<input type="text" id="newteditypetitle" style="width: 100px">
                <a href="#" class="easyui-linkbutton" onclick="bt_editType()">保存</a>
                <a href="#" class="easyui-linkbutton" onclick="$('#newsTypeEditwin').dialog('close')">关闭</a>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $('#newTypelist').datagrid({
            url: '../admin/GetNwsTypeList',
            singleSelect: true,
            columns: [[
                { field: 'title', title: '新闻类型', width: 200 },
             { field: 'time', title: '发表时间', width: 200 },
                 {
                     field: 'opt', title: '修改操作', width: 100, align: 'center',
                     formatter: function (value, rec) {
                         var btn = "<a href=" + "#" + " class=" + "easyui-linkbutton" + " iconcls=" + "icon-edit" + " onclick=" + "editnewType(" + rec +")" + " plain=" + "true" + ">编辑</a>";
                         return btn;
                     }
                 }
             ]]
         }); 
        var id;
         function addnewType() {
             $('#newsTypeaddwin').dialog('open');
         };
         function editnewType(rec) {
             id = rec.ID;
             $('newteditypetitle').val(rec.title);
             $('#newsTypeEditwin').dialog('open');
         };
         function  bt_addType() {
             var ti = $('newtaddypetitle').val();
             $.post("/admin/AddNewsType", { "title": ti },
                    function (data) {
                        if (data != "0") {
                            alert("添加成功");
                        }
                        else {
                            alert("添加失败");
                        }
                    });
         };

         function  bt_editType() {
             var ti = $('newteditypetitle').val();
             $.post("/admin/UpdataNewsType", { "title": ti },
                   function (data) {
                       if (data == "ok") {
                           alert("修改成功");
                       }
                       else {
                           alert("修改失败");
                       }
                   });
         };

         function delnewType() {
             var row = $('#newTypelist').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert('提示', '请选择需要删除的新闻');
             } else if (row.length > 1) {
                 $.messager.alert('提示', '只能同时删除一行数据，请重新选择');
             } else {
                 $.post("../admin/DeletNewsType", { ID: row.ID },
                function (data) {
                    if (data == false) {
                        $.messager.alert('未知错误', '删除失败.');
                    }
                    else {
                        $.messager.alert('提示', '删除成功');
                        $('#newlist').datagrid('load', {
                            code: '01',
                            name: 'name'
                        });
                    }
                });
             }
         };
    </script>
</body>
</html>
